package com.tcfvic.client.panels.widgets;

import java.util.Date;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.ListBox;
import com.tcfvic.client.PersonService;
import com.tcfvic.client.PersonServiceAsync;
import com.tcfvic.client.pojos.Logs;

public class LogsWidget extends FlexTable {

	private final PersonServiceAsync personService = GWT
			.create(PersonService.class);

	public LogsWidget() {
		super();

		// Create a table to layout the form options
		setCellSpacing(1);
		setWidth("100%");
		FlexCellFormatter cellFormatter = getFlexCellFormatter();

		// Add a title to the form
		setHTML(0, 0, "Add/Edit RTO data");
		cellFormatter.setColSpan(0, 0, 4);
		cellFormatter.setHorizontalAlignment(0, 0,
				HasHorizontalAlignment.ALIGN_CENTER);

		// Add a title to the form
		setHTML(0, 0, "Todays logs");
		
		final ListBox multiBox = new ListBox(true);
		multiBox.setSize("900px", "200px");
		
		personService.getAllLogs(new Date(), new AsyncCallback<List<Logs>>() {

			@Override
			public void onFailure(Throwable caught) {
				caught.printStackTrace();
				
			}

			@Override
			public void onSuccess(List<Logs> result) {
				int i = 1;
				for (Logs log : result) {
//					multiBox.addItem(log.getDateandtime() + " " + log.getText());
					setHTML(i++, 0, log.getText());
				}
				
			}
		});
		
	}
}
